package com.neuedu.shop.service.impl;

import java.util.List;

import com.neuedu.shop.mapper.AdminMapper;
import com.neuedu.shop.pojo.Admin;
import com.neuedu.shop.service.AdminService;
import com.neuedu.shop.util.ServletUtil;



/**
 * @author MrDCG
 * @version 创建时间：2019年9月16日 下午4:08:49
 *
 */
public class AdminServiceImpl implements AdminService {
	AdminMapper mapper;

	public AdminServiceImpl() {
	}

	public AdminServiceImpl(AdminMapper mapper) {
		this.mapper = mapper;
	}

	@Override
	public List<Admin> findAll() {
		return mapper.findAll();
	}

	@Override
	public void insert(Admin admin) {
		mapper.insert(admin);
	}

	@Override
	public Admin findById(int id) {
		return mapper.findById(id);
	}

	@Override
	public void update(Admin admin) {
		mapper.update(admin);
	}

	@Override
	public void delete(int id) {
		mapper.delete(id);
	}

	@Override
	public Admin login(String aname, String apwd) {
		Admin admin = mapper.findByAname(aname);
		if(admin != null) {
			if(admin.getAdminPassword().equals(ServletUtil.md5(apwd))) {
				return admin;
			}
			return null;
		}
		
		return null;
	}

	@Override
	public Admin findByAname(String adminName) {
		return mapper.findByAname(adminName);
	}

	@Override
	public void resetPassword(int id) {
		mapper.resetPassword(id);
	}

}
